package com.example.myapplication.apter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.myapplication.R;
import com.example.myapplication.ShuJu.HotjobBean;

import java.util.List;

public class HotjobApter extends RecyclerView.Adapter<HotjobApter.Myhot> {

    private Context context;
    private String TAG = "TAG";
    private List<HotjobBean.RowsBean> list;
    private String name;

    public HotjobApter(Context context, List<HotjobBean.RowsBean> list, String name) {
        this.context = context;
        this.list = list;
        this.name = name;
    }

    public HotjobApter(Context context, List<HotjobBean.RowsBean> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public HotjobApter.Myhot onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.item_hotjob, null);
        return new HotjobApter.Myhot(inflate);
    }

    @Override
    public void onBindViewHolder(@NonNull HotjobApter.Myhot holder, int position) {
        if (!TextUtils.isEmpty(name)) {
            if(!TextUtils.isEmpty(list.get(position).getAddress())){
                holder.address.setText(list.get(position).getAddress());
            }else {
                holder.address.setText("暂无");
            }

            if(!TextUtils.isEmpty(list.get(position).getName())){
                holder.name.setText(list.get(position).getName());
            }else {
                holder.address.setText("暂无");
            }

            if(!TextUtils.isEmpty(list.get(position).getSalary())){
                holder.salary.setText(list.get(position).getSalary());
            }else {
                holder.address.setText("暂无");
            }

            if(!TextUtils.isEmpty(list.get(position).getNeed())){
                holder.need.setText(list.get(position).getNeed());
            }else {
                holder.address.setText("暂无");
            }


        } else {
            if(!TextUtils.isEmpty(list.get(position).getAddress())){
                holder.address.setText(list.get(position).getAddress());
            }else {
                holder.address.setText("暂无");
            }

            if(!TextUtils.isEmpty(list.get(position).getName())){
                holder.name.setText(list.get(position).getName());
            }else {
                holder.address.setText("暂无");
            }

            if(!TextUtils.isEmpty(list.get(position).getSalary())){
                holder.salary.setText(list.get(position).getSalary());
            }else {
                holder.address.setText("暂无");
            }

            if(!TextUtils.isEmpty(list.get(position).getNeed())){
                holder.need.setText(list.get(position).getNeed());
            }else {
                holder.address.setText("暂无");
            }
        }

    }

    @Override
    public int getItemCount() {
        return list == null ? 0 : list.size();
    }

    class Myhot extends RecyclerView.ViewHolder {


        private final TextView address;
        private final TextView name;
        private final TextView need;
        private final TextView salary;

        public Myhot(@NonNull View itemView) {
            super(itemView);

            address = itemView.findViewById(R.id.address);
            name = itemView.findViewById(R.id.name);
            need = itemView.findViewById(R.id.need);
            salary = itemView.findViewById(R.id.salary);
        }
    }
}

